package org.shj.book2.chapter06.improve;

public class ReaderThread extends Thread{

	private final Data data;
	
	private volatile boolean flag = true;
	
	public ReaderThread(Data data){
		this.data = data;
	}
	
	public void run(){
		try{
			while(flag){
				char[] readbuf = data.read();
				System.out.println(Thread.currentThread().getName() + " reads: " + String.valueOf(readbuf));
				//Thread.sleep(10);
			}
		}catch(InterruptedException e){
			
		}
	}
	
	public void terminate(){
		this.flag = false;
	}
}
